package com.pascuit.gpxhandler.client;

import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VLayout;

public class WaitPopup {

	private final Canvas canvas = createModalMessage();
	private Label label;

	public void show() {
		setMessage();
		canvas.show();
	}

	private void setMessage() {
		label.setContents("Loading...");
	}

	public void hide() {
		canvas.hide();
	}

	private Canvas createModalMessage() {
		label = new Label();
		label.setWidth(200);
		label.setHeight100();
		label.setValign(VerticalAlignment.CENTER);

		HLayout hLayout = new HLayout();
		hLayout.setLayoutMargin(20);
		hLayout.setMembersMargin(5);

		VLayout vLayout = new VLayout();
		hLayout.setMembers(new LayoutSpacer(), vLayout, label,
				new LayoutSpacer());

		Window window = new Window();
		window.setShowHeader(false);
		window.setShowHeaderBackground(false);
		window.setShowHeaderIcon(false);
		window.setIsModal(true);
		window.setShowModalMask(true);
		window.setWidth(300);
		window.setHeight(120);
		window.addItem(hLayout);
		window.centerInPage();
		return window;
	}
}